package tickets.tickets;

import java.util.Date;

/**
 *
 * @author Hlib_Babii
 */
public class LimitedDurationTicket extends LimitedTicket {

    private Date expirationDate;

    LimitedDurationTicket(Ticket baseTicket, Date expirationDate) {
        super(baseTicket);
        this.expirationDate = expirationDate;
    }
    
    /**
     * Removes 1 travel from the ticket and returns whether passage was 
     * successful or not
     * @return true if passage was successful, false otherwise
     */
    @Override
    PassageState check() {
        PassageState ps = (System.currentTimeMillis() < expirationDate.getTime()) ? 
                PassageState.ALLOWED : PassageState.TICKET_EXPIRED;
        if (ps.passageAllowed()) {
            return baseTicket.check();
        } 
        return ps;
    }

    @Override
    void use() {
        baseTicket.use();
    }
    
}
